<?=$this->Style()->IncludeStyleFile(array('js' => 'ckfinder'), false, false, false);?>
<script type="text/javascript">
function SetFileField_<?=$this->fieldId;?>( fileUrl )
{
	var rootPaths = ['<?php echo _ROOT_URL; ?>', '<?php echo _ROOT_URL_STATIC; ?>'];
	var thumbPath = '<?php echo $this->data['thumbPath']; ?>';
	var data = '';
	var origFileUrl = fileUrl;
	
	if (fileUrl)
	{
		var x;
		for (x in rootPaths)
		{
			if (fileUrl.indexOf(rootPaths[x]) == 0) fileUrl = fileUrl.substr(rootPaths[x].length);
		}

		data = $('<img>').attr('alt', '').attr('src', thumbPath+fileUrl);
	}
	
	$('#image_<?=$this->fieldId;?>').html(data);
  	$('#filef_<?=$this->fieldId;?>').val(origFileUrl);
}

$(document).ready(
  function()
  {
	$("#button_<?=$this->fieldId;?>").click(
		function(e)
		{
			var finder = new CKFinder();
			finder.basePath = '<?=_FILEMANAGER_URL;?>';
			finder.selectActionFunction = SetFileField_<?=$this->fieldId;?>;
			finder.popup();
		}
	);
  }
);
</script>
<div id="image_<?=$this->fieldId;?>"><?php
if ($this->data['thumbnail'])
{
	?><img src="<?php echo htmlspecialchars($this->data['thumbnail']); ?>" alt=""><?php
}
?></div>
<input type="hidden" name="<?=$this->fieldName;?>[file]" id="filef_<?=$this->fieldId;?>" value="<?=htmlspecialchars($this->data['file']);?>">
<input type="button" id="button_<?=$this->fieldId;?>" value="<?php echo Mozg_Lang::_('CHOOSE'); ?>" class="bt" />
